#![allow(unused_imports)]
use super::DataTransferObject;
use crate::order::Order;
use anyhow::Result;
use bytes::Bytes;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, DataTransferObject)]
pub struct Orderstack {
    pub price: f32,
    pub volume: u32,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, DataTransferObject)]
pub struct TickData {
    pub timestamp_us: u64, // 时间戳(microseconds)
    pub symbol: String, // 品种
    pub last: f32, // 最后成交价
    pub asks: Vec<Orderstack>, // '卖'数组, 价格正序 
    pub bids: Vec<Orderstack>, // '买'数组, 价格倒序
    /// 不参与传输但是要参与回测
    #[serde(skip)]
    pub limit_up: Option<f32>, // 涨停价
    #[serde(skip)]
    pub limit_down: Option<f32>, // 跌停价
}


impl TickData {
    pub fn new(
        timestamp_us: u64,
        symbol: String,
        last: f32,
        asks: Vec<Orderstack>,
        bids: Vec<Orderstack>,
    ) -> Self {
        TickData {
            timestamp_us,
            symbol,
            last,
            asks,
            bids,
            limit_up: None, // 默认值
            limit_down: None, // 默认值
        }
    }
}

/// Orderbooks数据结构
/// 不用正反序列化, 仅在matchmake时使用
/// 在core中实现
#[derive(Debug, Clone)]
pub struct Orderbooks{
    pub asks: Vec<Orderstack>, // 卖单
    pub bids: Vec<Orderstack>, // 买单
}